clear all

use tracker.dta, clear


*K6SUM VARIABLE FOR KESSLER PSYCHOLOGICAL DISTRESS SCALE* https://meps.ipums.org/meps-action/variables/K6SUM#description_section ... AFTER WAVE 1 BASELINE
replace depressed_howoften=. if depressed_howoften==97 | depressed_howoften==98
recode depressed_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

replace nervous_howoften=. if nervous_howoften==97 | nervous_howoften==98
recode nervous_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

replace restless_howoften=. if restless_howoften==97 | restless_howoften==98 | restless_howoften==99
recode restless_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

replace hopeless_howoften=. if hopeless_howoften==97 | hopeless_howoften==98 |  hopeless_howoften==99
recode hopeless_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

replace effort_howoften=. if effort_howoften==97 | effort_howoften==98 | effort_howoften==99
recode effort_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

replace worthless_howoften=. if worthless_howoften==97 | worthless_howoften==98 | worthless_howoften==99
recode worthless_howoften (5=0) (4=1) (3=2) (2=3) (1=4)

egen distress = rowtotal(depressed_howoften nervous_howoften restless_howoften hopeless_howoften effort_howoften worthless_howoften) if depressed_howoften !=. & nervous_howoften !=. & restless_howoften !=. & hopeless_howoften !=. & effort_howoften !=. & worthless_howoften !=.


*cleaning
gen received_assistance=.
replace received_assistance=0 if wic_12mos==0 | houseassist_12mos==0 | medicaid_12mos==0 | imp_snap_12mos==0 | imp_retirement_12mos==0 | imp_disability_12mos==0 | imp_welfare_12mos==0 | imp_unemployment_12mos==0 | imp_regcashassist_12mos==0 |imp_otherbenefits ==0
replace received_assistance=1 if wic_12mos==1 | houseassist_12mos==1 | medicaid_12mos==1 | imp_snap_12mos==1 | imp_retirement_12mos==1 | imp_disability_12mos==1 | imp_welfare_12mos==1 | imp_unemployment_12mos==1 | imp_regcashassist_12mos==1 | imp_otherbenefits ==1

drop age
rename imp_qage_tc age
drop female
rename imp_female female
drop rent_hardship
rename imp_rent_hardship rent_hardship
drop moved_finances
rename imp_moved_finances moved_finances
drop moved_temporary
rename imp_moved_temporary moved_temporary
drop energy_bill
rename imp_energy_bill energy_bill
drop disconnected
rename imp_disconnected disconnected
drop skipped_healthcare
rename imp_skipped_healthcare skipped_healthcare
drop ranout_money
rename imp_ranout_money ranout_money
drop food_insufficient
rename imp_food_insufficient food_insufficient
drop food_runout_worry
rename imp_food_runout_worry food_runout_worry
drop food_ranout
rename imp_food_ranout food_ranout

recode imp_genhealth_rating (5=1) (4=2) (2=4) (1=5)
lab define ghealthlab 1 "Poor" 2 "Fair" 3 "Good" 4 "Very Good" 5 "Excellent"
label val imp_genhealth_rating ghealthlab

replace generalhealth_rating =1 if imp_genhealth_rating==1 | generalhealth_rating==1
replace generalhealth_rating =2 if imp_genhealth_rating==2 | generalhealth_rating==2
replace generalhealth_rating =3 if imp_genhealth_rating==3 | generalhealth_rating==3
replace generalhealth_rating =4 if imp_genhealth_rating==4 | generalhealth_rating==4
replace generalhealth_rating =5 if imp_genhealth_rating==5 | generalhealth_rating==5

order person_weight month year, after(id)
rename imp_qchwoop_tc childcare_expenses
rename imp_qmoop_tc medical_expenses
rename imp_q3creditcarddebt_d credit_debt
rename imp_q3medicaldebt_d medical_debt
rename imp_q3otherdebt_d other_debt

gen owe_debt = 0 if credit_debt ==2 | medical_debt==2 | other_debt==2
replace owe_debt = 1 if credit_debt ==1 | medical_debt==1 | other_debt==1

keep id person_weight poverty_weight month year white black asian hispanic race_other homeowner renter female monthly_rent_mortgage bedrooms freefood homeless_facility generalhealth_rating disability_preventwork money_worries_howoften life_rating workedforpay_lastweek received_assistance children_under18 hh_adults hh_size race educ age months_worked spousemonths_worked rent_hardship moved_finances moved_temporary energy_bill disconnected skipped_healthcare ranout_money food_insufficient food_runout_worry food_ranout borough foodhardship_moderate househardship_moderate energyhardship_moderate financialhardship_moderate foodhardship_severe househardship_severe energyhardship_severe financialhardship_severe medicalhardship_24mos severe_hardship earnings spouse_earnings childcare_expenses medical_expenses spm_poverty_status physicalhealth_rating mentalhealth_rating owe_debt distress wic_12mos houseassist_12mos medicaid_12mos imp_snap_12mos imp_retirement_12mos imp_disability_12mos imp_welfare_12mos imp_unemployment_12mos imp_regcashassist_12mos imp_otherbenefits wave

gen household_earnings= earnings + spouse_earnings

gen energyhardship_modsev =1 if energyhardship_moderate==1 | energyhardship_severe ==1
replace energyhardship_modsev = 0 if energyhardship_modsev !=1
gen foodhardship_modsev =1 if foodhardship_moderate==1 | foodhardship_severe==1
replace foodhardship_modsev =0  if foodhardship_modsev !=1
gen househardship_modsev =1 if househardship_moderate==1 | househardship_severe==1
replace househardship_modsev =0 if househardship_modsev !=1
gen financialhardship_modsev=1 if financialhardship_moderate==1 | financialhardship_severe==1
replace financialhardship_modsev = 0 if financialhardship_modsev !=1

save sample_hardship.dta, replace


**USE cleaned dataset**
use sample_hardship.dta, clear
set scheme s1color

gen any_hardship = 1 if energyhardship_modsev==1 | foodhardship_modsev==1 | househardship_modsev==1 | financialhardship_modsev==1 | medicalhardship_24mos==1
replace any_hardship = 0 if any_hardship !=1

svyset [pweight=person_weight]

replace bedrooms =. if bedrooms==97 | bedrooms==98 | bedrooms==99
gen other=0
replace other =1 if race==3 | race==4
xi i.borough
xi i.year

global controls black hispanic other female age renter household_earnings bedrooms disability_preventwork owe_debt received_assistance children_under18 hh_size
global fe i.borough i.year

label var energyhardship_moderate "Mod. Energy Hardship"
label var energyhardship_severe "Sev. Energy Hardship"
label var foodhardship_moderate "Mod. Food Hardship"
label var foodhardship_severe "Sev. Food Hardship"
label var househardship_moderate "Mod. Housing Hardship"
label var househardship_severe "Sev. Housing Hardship"
label var financialhardship_moderate "Mod. Finance Hardship"
label var financialhardship_severe "Sev. Finance Hardship"
label var medicalhardship_24mos "Medical Hardship"



*********************************************************************************
*Vars for logits -- physical health poor or good, general health poor or good
*********************************************************************************
gen genhealth_good=.
replace genhealth_good=0 if generalhealth_rating == 1 | generalhealth_rating ==2
replace genhealth_good=1 if generalhealth_rating == 3 | generalhealth_rating ==4 | generalhealth_rating ==5

gen physhealth_good=.
replace physhealth_good=0 if physicalhealth_rating == 1 | physicalhealth_rating ==2
replace physhealth_good=1 if physicalhealth_rating == 3 | physicalhealth_rating ==4 | physicalhealth_rating ==5


*********************************************************************************
*Appendix Figure S1 - physical health rating binary
*********************************************************************************
logit physhealth_good energyhardship_moderate energyhardship_severe $controls i.borough [pweight=person_weight], vce(cluster borough)
est store ph1
logit physhealth_good foodhardship_moderate foodhardship_severe $controls i.borough [pweight=person_weight], vce(cluster borough)
est store ph2
logit physhealth_good househardship_moderate househardship_severe $controls i.borough [pweight=person_weight], vce(cluster borough)
est store ph3
logit physhealth_good financialhardship_moderate financialhardship_severe $controls i.borough [pweight=person_weight], vce(cluster borough)
est store ph4
logit physhealth_good medicalhardship_24mos $controls i.borough [pweight=person_weight], vce(cluster borough)
est store ph5

**Coefplot
coefplot ph1 ph2 ph3 ph4 ph5, keep(energyhardship_moderate energyhardship_severe foodhardship_moderate foodhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe medicalhardship_24mos) xline(0) legend(off) xlabel(0 -0.2 -0.4 -0.6 -0.8 -1.0 -1.2 -1.4) title("Physical Health Rating by Hardship Status", size(med) pos(bottom))
gr export FigureA1.png, replace

*********************************************************************************
*Appendix Table S1 - estimates with lags
*********************************************************************************
sort id year
by id: gen energy_lag = energyhardship_modsev[_n-1]
by id: gen food_lag = foodhardship_modsev[_n-1]
by id: gen house_lag = househardship_modsev[_n-1]
by id: gen finance_lag = financialhardship_modsev[_n-1]
by id: gen medical_lag = medicalhardship_24mos[_n-1]

logit genhealth_good energy_lag energyhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(energyhardship_modsev energy_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) replace
logit genhealth_good food_lag foodhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(foodhardship_modsev food_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
logit genhealth_good house_lag househardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(househardship_modsev house_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
logit genhealth_good finance_lag financialhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(financialhardship_modsev finance_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
logit genhealth_good medical_lag medicalhardship_24 $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(medicalhardship_24 medical_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

reg life_rating energy_lag energyhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(energyhardship_modsev energy_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg life_rating food_lag foodhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(foodhardship_modsev food_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg life_rating house_lag househardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(househardship_modsev house_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg life_rating finance_lag financialhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(financialhardship_modsev finance_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg life_rating medical_lag medicalhardship_24 $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(medicalhardship_24 medical_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

reg distress energy_lag energyhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(energyhardship_modsev energy_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg distress food_lag foodhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(foodhardship_modsev food_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg distress house_lag househardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(househardship_modsev house_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg distress finance_lag financialhardship_modsev $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(financialhardship_modsev finance_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
reg distress medical_lag medicalhardship_24 $controls $fe [pweight=person_weight], vce(cluster borough)
outreg2 using TableS1.rtf, keep(medicalhardship_24 medical_lag ) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append


label var renter "Renter"
label var female "Female"
label var monthly_rent_mortgage "Housing payment"
label var bedrooms "Bedrooms"
label var disability_preventwork "Disability"
label var received_assistance "Gov't Assistance"
label var children_under18 "Children"
label var hh_size "Household Size"
label var black "Black"
label var hispanic "Hispanic"
label var other "Other Race"
label var educ "Educ"
label var workedforpay_lastweek "Worked last week"
label var earnings "Earnings"
label var household_earnings "HH earnings"
label var age "Age"
label var owe_debt "Owe debt"

**TABLE 1: DESCRIPTIVES**
**Outcomes**
svy: mean genhealth_good life_rating distress
estat sd

***Regressors**
svy: mean foodhardship_moderate foodhardship_severe energyhardship_moderate energyhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe
estat sd

***Controls***
svy: mean black hispanic female age renter household_earnings bedrooms disability_preventwork owe_debt received_assistance children_under18 hh_size borough
estat sd


************************************************************************************************************
*FIGURE 1: Mean Health Rating Over Time by Hardship Status*
************************************************************************************************************
drop if wave ==1
gen moderate_hardship=1 if foodhardship_moderate==1 | househardship_moderate==1 | energyhardship_moderate==1 | financialhardship_moderate==1
replace moderate_hardship=0 if moderate_hardship !=1

gen no_hardship=1 if severe_hardship==0 & moderate_hardship==0
replace no_hardship=0 if no_hardship !=1

*Create mean variables for each group
egen health_no_hardship = mean(genhealth_good) if no_hardship == 1, by(year)
egen health_hardship = mean(genhealth_good) if severe_hardship == 1, by(year)
egen health_medhardship = mean(genhealth_good) if moderate_hardship == 1, by(year)

sort year

set scheme s1color
twoway (line health_no_hardship year, legend(label(1 "No severe hardship"))) ///
       (line health_medhardship year, legend(label(2 "Moderate hardship"))) ///
       (line health_hardship year, legend(label(3 "Severe hardship"))), ///
       title("General Health Rating (Poor-Excellent) by Hardship Status", size(med)) ///
       ytitle("Rating", size(medsmall) alignment(center)) /// Adjust the Y-axis title position
       xtitle("Year", size(med)) ///
       ylabel(0 1) ///
       legend(order(1 2 3) row(1) size(small))
gr save tmp1.gph, replace
gr export health_no_mod_sev.png, replace

*Create mean variables for each group
egen rate_no_hardship = mean(life_rating) if no_hardship == 1, by(year)
egen rate_hardship = mean(life_rating) if severe_hardship == 1, by(year)
egen rate_medhardship = mean(life_rating) if moderate_hardship ==1, by(year)

sort year


set scheme s1color
twoway (line rate_no_hardship year, legend(label(1 "No severe hardship"))) ///
       (line rate_medhardship year, legend(label(2 "Moderate hardship"))) ///
       (line rate_hardship year, legend(label(3 "Severe hardship"))), ///
       title("Life rating (0-10) by Hardship Status", size(med)) ///
       ytitle("Rating", size(medsmall) alignment(center)) /// Adjust the Y-axis title position
       xtitle("Year", size(med)) ///
	   ylabel(5.5 6.0 6.5 7.0 7.5 8.0) ///
       legend(order(1 2 3) row(1) size(small))
gr save tmp2.gph, replace
gr export health_no_mod_sev.png, replace


*Create mean variables for each group
egen distress_no_hardship = mean(distress) if no_hardship == 1, by(year)
egen distress_hardship = mean(distress) if severe_hardship == 1, by(year)
egen distress_medhardship = mean(distress) if moderate_hardship ==1, by(year)

twoway (line distress_no_hardship year, legend(label(1 "No severe hardship"))) ///
       (line distress_medhardship year, legend(label(2 "Moderate hardship"))) ///
       (line distress_hardship year, legend(label(3 "Severe hardship"))), ///
       title("Distress", size(med)) ///
	   ylabel(1 2 3 4 5 6 7 8 9 10) ///
       legend(order(1 2 3) row(1) size(small))
gr save tmp3.gph, replace
gr export distress_no_mod_sev.png, replace

*****COMINE GRAPHS*****
label var health_no_hardship "No Hardship"
label var health_medhardship "Moderate Hardship"
label var health_hardship "Severe Hardship"

twoway (line health_no_hardship year, lpattern(solid)) ///
       (line health_medhardship year, lpattern(shortdash_dot)) ///
       (line health_hardship year, lpattern(dash)), ///
       title("General Health Rating", size(med)) ///
	          xtitle("", size(med)) ///
       ylabel(0 0.5 1) ///
       legend(order(1 2 3) row(1) size(small)) ///
	   ysize (15) xsize(30)
gr save tmp1.gph, replace

twoway (line rate_no_hardship year, lpattern(solid)) ///
       (line rate_medhardship year, lpattern(shortdash_dot)) ///
       (line rate_hardship year, lpattern(dash)), ///
       title("Life rating", size(med)) ///
	          xtitle("", size(med)) ///
	   ylabel(0 2 4 6 8 10) ///
       legend(order(1 2 3) row(1) size(small)) ///
	   ysize (15) xsize(30)
gr save tmp2.gph, replace

twoway (line distress_no_hardship year, lpattern(solid)) ///
       (line distress_medhardship year, lpattern(shortdash_dot)) ///
       (line distress_hardship year, lpattern(dash)), ///
       title("Distress Scale", size(med)) ///
       xtitle("", size(med)) ///
	   ylabel(0 4 8 12 16 20 24) ///
       legend(order(1 2 3) row(1) size(small)) ///
	   ysize (15) xsize(30)
gr save tmp3.gph, replace

grc1leg tmp1.gph tmp2.gph tmp3.gph, row(1) name(grc1leg, replace)
gr draw grc1leg, ysize(47) xsize(100)
gr export fig1.png, replace



************************************************************************************************************
*FIGURE 2 and FIGURE 3: Physical and Mental Health Coefficient Plots
************************************************************************************************************
logit genhealth_good energyhardship_moderate energyhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store health1
logit genhealth_good energyhardship_moderate energyhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(energyhardship_moderate energyhardship_severe) post
est sto h1
logit genhealth_good foodhardship_moderate foodhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store health2
logit genhealth_good foodhardship_moderate foodhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(foodhardship_moderate foodhardship_severe) post
est sto h2
logit genhealth_good househardship_moderate househardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store health3
logit genhealth_good househardship_moderate househardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(househardship_moderate househardship_severe) post
est sto h3
logit genhealth_good financialhardship_moderate financialhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store health4
logit genhealth_good financialhardship_moderate financialhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(financialhardship_moderate financialhardship_severe) post
est sto h4
logit genhealth_good medicalhardship_24mos $controls $fe [pweight=person_weight], vce(cluster borough)
est store health5
logit genhealth_good medicalhardship_24mos $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(medicalhardship_24mos) post
est sto h5


**********
reg life_rating energyhardship_moderate energyhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store lr1
reg life_rating foodhardship_moderate foodhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store lr2
reg life_rating househardship_moderate househardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store lr3
reg life_rating financialhardship_moderate financialhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store lr4
reg life_rating medicalhardship_24mos $controls $fe [pweight=person_weight], vce(cluster borough)
est store lr5


*********
reg distress energyhardship_moderate energyhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store ds1
reg distress foodhardship_moderate foodhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store ds2
reg distress househardship_moderate househardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store ds3
reg distress financialhardship_moderate financialhardship_severe $controls $fe [pweight=person_weight], vce(cluster borough)
est store ds4
reg distress medicalhardship_24mos $controls $fe [pweight=person_weight], vce(cluster borough)
est store ds5

**********
*FIGURE 2
**********
/*
coefplot health1 health2 health3 health4 health5, keep(energyhardship_moderate energyhardship_severe foodhardship_moderate foodhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe medicalhardship_24mos) xline(0) legend(off) xlabel(0 -0.5 -1.0  -1.5) title("General Health Rating by Hardship Status", size(med) pos(bottom))
gr export Figure2.png, replace
*/
**AME
coefplot h1 h2 h3 h4 h5, keep(energyhardship_moderate energyhardship_severe foodhardship_moderate foodhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe medicalhardship_24mos) xline(0) legend(off) xlabel(0 -0.05 "5%" -0.1 "10%" -0.15 "15%") title("General Health Rating by Hardship Status", size(med) pos(bottom))
gr export Fig2.png, replace


**********
*FIGURE 3
**********
coefplot lr1 lr2 lr3 lr4 lr5, keep(energyhardship_moderate energyhardship_severe foodhardship_moderate foodhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe medicalhardship_24mos) xline(0) legend(off) xlabel(0 -0.5 -1 -1.5 -2 -2.5) title("Life Rating", size(med) pos(bottom))
gr save lr.gph, replace

coefplot ds1 ds2 ds3 ds4 ds5, keep(energyhardship_moderate energyhardship_severe foodhardship_moderate foodhardship_severe househardship_moderate househardship_severe financialhardship_moderate financialhardship_severe medicalhardship_24mos) xline(0) legend(off) xlabel(0 1 2 3 4 5 6) title("Distress Scale", size(med) pos(bottom))
gr save ds.gph, replace

gr combine lr.gph ds.gph, xsize(10) ysize(5)
gr export Figure3.png, replace


************************************************************************************************************
*Table 2: Acute vs chronic
************************************************************************************************************
*FOOD
***ACUTE VS CHRONIC***
bysort id: egen total_food = total(foodhardship_modsev)
* Create the acute vs. chronic
gen food_type = 0 if total_food==0
replace food_type = 1 if total_food == 1 // Acute
replace food_type = 2 if total_food > 1  // Chronic
label define food_type 1 "Acute" 2 "Chronic"
label values food_type food_type
gen food_chronic=0
replace food_chronic=1 if food_type==2
tab food_type
svy: mean food_chronic

*ENERGY
bysort id: egen total_energy = total(energyhardship_modsev)
gen energy_type = 0 if total_energy==0
replace energy_type = 1 if total_energy == 1 // Acute
replace energy_type = 2 if total_energy > 1  // Chronic
label define energy_type 1 "Acute" 2 "Chronic"
label values energy_type energy_type
gen energy_chronic=0
replace energy_chronic=1 if energy_type==2
tab energy_type
svy: mean energy_chronic

*HOUSING
bysort id: egen total_house = total(househardship_modsev)
gen house_type = 0 if total_house==0
replace house_type = 1 if total_house == 1 // Acute
replace house_type = 2 if total_house > 1  // Chronic
label define house_type 1 "Acute" 2 "Chronic"
label values house_type house_type
gen house_chronic=0
replace house_chronic=1 if house_type==2
tab house_type
svy: mean house_chronic

*FINANCIAL
bysort id: egen total_financial = total(financialhardship_modsev)
gen financial_type = 0 if total_financial==0
replace financial_type = 1 if total_financial == 1 // Acute
replace financial_type = 2 if total_financial > 1  // Chronic
label define financial_type 1 "Acute" 2 "Chronic"
label values financial_type financial_type
gen financial_chronic=0
replace financial_chronic=1 if financial_type==2
tab financial_type
svy: mean financial_chronic

*MEDICAL
bysort id: egen total_medical = total(medicalhardship_24mo)
gen medical_type = 0 if total_medical==0
replace medical_type = 1 if total_medical == 1 // Acute
replace medical_type = 2 if total_medical > 1  // Chronic
label define medical_type 1 "Acute" 2 "Chronic"
label values medical_type medical_type
gen medical_chronic=0
replace medical_chronic=1 if medical_type==2
tab medical_type
svy: mean medical_chronic


*general health by acute vs chronic
logit genhealth_good i.food_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store food
logit genhealth_good i.food_type $controls $fe [pweight=person_weight], vce(cluster borough)
margins, dydx(i.food_type) post
est store food2
logit genhealth_good i.energy_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store energy
margins, dydx(i.energy_type) post
est store energy2
logit genhealth_good i.house_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store house
margins, dydx(i.house_type) post
est store house2
logit genhealth_good i.financial_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store financial
margins, dydx(i.financial_type) post
est store financial2
logit genhealth_good i.medical_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store medical
margins, dydx(i.medical_type) post
est store medical2

esttab food energy house financial medical using genhealth_tab.rtf, replace se keep(1.food_type 2.food_type 1.energy_type 2.energy_type 1.house_type 2.house_type 1.financial_type 2.financial_type 1.medical_type 2.medical_type)
**AMEs
esttab food2 energy2 house2 financial2 medical2 using genhealth_tab_me.rtf, replace se keep(1.food_type 2.food_type 1.energy_type 2.energy_type 1.house_type 2.house_type 1.financial_type 2.financial_type 1.medical_type 2.medical_type)


*life rating by acute vs chronic
reg life_rating i.food_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store food
reg life_rating i.energy_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store energy
reg life_rating i.house_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store house
reg life_rating i.financial_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store financial
reg life_rating i.medical_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store medical

esttab food energy house financial medical using liferate_tab.rtf, replace se keep(1.food_type 2.food_type 1.energy_type 2.energy_type 1.house_type 2.house_type 1.financial_type 2.financial_type 1.medical_type 2.medical_type)


**distress by acute vs chronic
reg distress i.food_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store food
reg distress i.energy_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store energy
reg distress i.house_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store house
reg distress i.financial_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store financial
reg distress i.medical_type $controls $fe [pweight=person_weight], vce(cluster borough)
est store medical

esttab food energy house financial medical using distress_tab.rtf, replace se keep(1.food_type 2.food_type 1.energy_type 2.energy_type 1.house_type 2.house_type 1.financial_type 2.financial_type 1.medical_type 2.medical_type)



************************************************************************************************************
*FIGURE 4: HARDSHIP COUNT
************************************************************************************************************
egen hardship_count = rowtotal(energyhardship_modsev foodhardship_modsev househardship_modsev financialhardship_modsev medicalhardship_24mos)
logit genhealth_good i.hardship_count $controls $fe [pweight=person_weight], vce(cluster borough)
margins, at(hardship_count=(0(1)5))
marginsplot, title("General Health Rating") ylabel(0.6 "0.6" 0.7 "0.7" 0.8 "0.8" 0.9 "0.9") xtitle("") ytitle("")
gr save genmar.gph, replace

reg life_rating i.hardship_count $controls $fe [pweight=person_weight], vce(cluster borough)
margins, at(hardship_count=(0(1)5))
marginsplot, title("Life Rating") xtitle("") ytitle("") ylabel(5.0 5.5 6.0 6.5 7.0 7.5 8.0)
gr save lifemar.gph, replace

reg distress i.hardship_count $controls $fe [pweight=person_weight], vce(cluster borough)
margins, at(hardship_count=(0(1)5))
marginsplot, title("Distress Scale") ylabel(2 3 4 5 6 7 8 9 10) xtitle("") ytitle("")
gr save dismar.gph, replace

gr combine genmar.gph lifemar.gph dismar.gph, title("Health Outcome by Hardship Count", pos(bottom)) row(1) xsize(10) ysize(3.5) l1("Linear Prediction")
gr export Figure4.png, replace




************************************************************************************************************
*Appendix Table S2
************************************************************************************************************
gen any_moderate = 1 if energyhardship_moderate==1 | foodhardship_moderate==1 | househardship_moderate==1 | financialhardship_moderate==1
replace any_moderate = 0 if any_moderate !=1

gen any_severe = 1 if energyhardship_severe==1 | foodhardship_severe==1 | househardship_severe==1 | financialhardship_severe==1
replace any_severe = 0 if any_severe !=1

***Seemingly unrelated regressions***
sureg (genhealth_good energyhardship_moderate energyhardship_sev $controls $fe) (life_rating energyhardship_moderate energyhardship_sev $controls $fe) (distress energyhardship_moderate energyhardship_sev $controls $fe)
outreg2 using TableS2.rtf, keep(energyhardship_moderate energyhardship_sev) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) replace

sureg (genhealth_good foodhardship_moderate foodhardship_sev $controls $fe) (life_rating foodhardship_moderate foodhardship_sev $controls $fe) (distress foodhardship_moderate foodhardship_sev $controls $fe)
outreg2 using TableS2.rtf, keep(foodhardship_moderate foodhardship_sev) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

sureg (genhealth_good househardship_moderate househardship_sev $controls $fe) (life_rating househardship_moderate househardship_sev $controls $fe) (distress househardship_moderate househardship_sev $controls $fe)
outreg2 using TableS2.rtf, keep(househardship_moderate househardship_sev) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

sureg (genhealth_good financialhardship_moderate financialhardship_sev $controls $fe) (life_rating financialhardship_moderate financialhardship_sev $controls $fe) (distress financialhardship_moderate financialhardship_sev $controls $fe)
outreg2 using TableS2.rtf, keep(financialhardship_moderate financialhardship_sev) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

sureg (genhealth_good medicalhardship_24mos $controls $fe) (life_rating medicalhardship_24mos $controls $fe) (distress medicalhardship_24mos $controls $fe)
outreg2 using TableS2.rtf, keep(medicalhardship_24mos) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append